ValueFolderTemp='C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\ResultsJournal\';
ValueFolderTemp2='C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\ResultsEditor\';
load([ValueFolderTemp 'ResultsThirdLevelDistributionOutliers.mat']);
VecDistribution=VecResults;
load('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\EtudeNature.mat');
VecEditors1Temp(1,:)=[];
VecValueEditor=VecEditors1Temp;
load('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\DonneesNature.mat');
VecValueJournal=VecJournalTemp;
VecValueJournalStart=xlsread('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\pubmed\DonneesNature.xlsx',1);
ValueCutoff=1.25;
VecFigure=[];
VecFigure2=[];
VecFigure3=[];
VecFigure5=[];
VecResultsCoAuthors=[];
VecResultsCoAuthors2=[];
VecResultsCoAuthors3=[];
VecResultsEditorsCoAuthorsTemp=zeros(1,4);
VecResultsEditorAfter=[];
VecResultsEditorBefore=[];
VecResultsEditorTemp2=[];
VecResultsEditorCoAuthors=[];
VecResultsEditorCoAuthors2=[];
VecResultsEditorJournal=[];
VecResultsEditorJournal2=[];
for n1=1:323
    n1
    ValueTemp=find(VecDistribution(:,1)==n1);
    ValueStartEditor=VecValueEditor{n1,22};
    n5Temp5=0;
    if size(ValueTemp,1)==1&&n1~=11
        if VecDistribution(ValueTemp,2)<=ValueCutoff
            ValueJournal=VecValueEditor{n1,11};
            n3=1;
            TestTemp=0;
            while n3<=size(VecValueJournal,1)&&TestTemp==0
                if strcmpi(ValueJournal,VecValueJournal{n3,1})==1
                    TestTemp=1;
                else
                    n3=n3+1;
                end
            end
%             ValueFileTemp4=dir([ValueFolderTemp2 'FileAnalysisEditorCoAuthors' num2str(n1) 'RestrictedYear2Month8.mat']);
%             if size(ValueFileTemp4,1)==1
                load([ValueFolderTemp2 'FileAnalysisEditorCoAuthors' num2str(n1) 'RestrictedYear2Month8.mat']);
                load([ValueFolderTemp2 'FileAnalysisCharacteristicsEditor' num2str(n1) '.mat']);
                VecValueTemp24=[];
                VecValueTemp25=[];
                VecValueTemp24Temp=[];
                VecValueTemp25Temp=[];
                ValueTime=clock();
                n5Temp=0;
                for n2=1:33
                    if n2==n3
                        eval(['VecValueTemp=VecResultsCoAuthors' num2str(n2) 'j1y1m2;']);
%                         eval(['VecValueTemp=VecResultsCoAuthors' num2str(n2) 'j1y1m2Filtered;']); % robustness analysis for the first group of co-authors
                        VecValueTemp22=VecValueTemp';
%                         if size(VecValueTemp,2)>=1 % To keep only co-authors who published before the editor's appointmenet in the anlaysis of article spublished by co-authors only in the editor's journal and the other journals
%                             ValueTemp4=find(VecValueTemp(2,:)>0);
%                             VecValueTemp22=VecValueTemp(:,ValueTemp4);
%                             VecValueTemp22=VecValueTemp22';
%                         else
%                             VecValueTemp22=[];
%                         end
                        eval(['VecValueTemp=VecResultsOtherAuthors' num2str(n2) 'j1y1m2;']);
%                         eval(['VecValueTemp=VecResultsOtherAuthors' num2str(n2) 'j1y1m2Filtered;']); % robustness analysis for the first group of co-authors
                        VecValueTemp23=VecValueTemp';
                    else
%                         if VecResultsEditor(1,16)<VecValueJournalStart(n2,5)||VecResultsEditor(1,16)>VecValueJournalStart(n2,6) % Exclusion of journals which have been launched during the two years after the editor's appointment (to be commented to get all journals)
                            eval(['VecValueTemp=VecResultsCoAuthors' num2str(n2) 'j1y1m1;']);
%                             if size(VecValueTemp,2)>=1 % To keep only co-authors who published before the editor's appointmenet in the anlaysis of article spublished by co-authors only in the editor's journal and the other journals
%                                 ValueTemp4=find(VecValueTemp(2,:)>0);
%                                 VecValueTemp=VecValueTemp(:,ValueTemp4);
%                                 eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1m;']);
%                                 VecValueTemp2=VecValueTemp2(:,ValueTemp4);
%                             end
%                             eval(['VecValueTemp=VecResultsCoAuthors' num2str(n2) 'j1y1m1Filtered;']); % robustness analysis for the first group of co-authors
                            if size(VecValueTemp24,2)==0&&size(VecValueTemp,2)>=1
                                VecValueTemp24=VecValueTemp;
                                VecValueTemp25=VecValueTemp;
                                eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1m;']);
%                                 eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1mFiltered;']); % robustness analysis for the first group of co-authors
                                VecValueTemp24Temp=VecValueTemp2;
                                n5Temp=n5Temp+1;
                            else
                                if size(VecValueTemp,2)>=1
                                    eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1m;']);
%                                     eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1mFiltered;']); % robustness analysis for the first group of co-authors
                                    for n4=1:size(VecValueTemp2,2)
                                        n5=1;
                                        TestTemp=0;
                                        while TestTemp==0&&n5<=size(VecValueTemp24Temp,2)
                                            if size(VecValueTemp24Temp{1,n5},2)==size(VecValueTemp2{1,n4},2)&&sum(abs(VecValueTemp24Temp{1,n5}-VecValueTemp2{1,n4}))==0
                                                TestTemp=1;
                                            else
                                                n5=n5+1;
                                            end
                                        end
                                        if n5<=size(VecValueTemp24Temp,2)
                                            VecValueTemp24(:,n5)=VecValueTemp24(:,n5)+VecValueTemp(:,n4);
                                        else
                                            VecValueTemp24(:,n5)=VecValueTemp(:,n4);
                                            VecValueTemp24Temp(1,n5)={VecValueTemp2{1,n4}};
                                        end
                                        n5Temp=n5Temp+1;
                                    end
                                    VecValueTemp25=[VecValueTemp25 VecValueTemp];
                                    if size(VecValueTemp2,2)>0
                                        n5Temp5=n5Temp5+1;
                                    end
                                end
                            end
%                         end
                    end
%                     eval(['VecValueTemp=VecResultsOtherAuthors' num2str(n2) 'j1y1m1;']);
%                     if size(VecValueTemp25,2)==0&&size(VecValueTemp,2)>=1
%                         VecValueTemp25=VecValueTemp;
%                         eval(['VecValueTemp2=VecResultsNameOtherAuthors' num2str(n2) 'j1y1m;']);
%                         VecValueTemp25Temp=VecValueTemp2;
%                     else
%                         if size(VecValueTemp,2)>=1
%                             eval(['VecValueTemp2=VecResultsNameOtherAuthors' num2str(n2) 'j1y1m;']);
%                             for n4=1:size(VecValueTemp2,2)
%                                 n5=1;
%                                 TestTemp=0;
%                                 while TestTemp==0&&n5<=size(VecValueTemp25Temp,2)
%                                     if size(VecValueTemp25Temp{1,n5},2)==size(VecValueTemp2{1,n4},2)&&sum(abs(VecValueTemp25Temp{1,n5}-VecValueTemp2{1,n4}))==0
%                                         TestTemp=1;
%                                     else
%                                         n5=n5+1;
%                                     end
%                                 end
%                                 if n5<=size(VecValueTemp25Temp,2)
%                                     VecValueTemp25(:,n5)=VecValueTemp25(:,n5)+VecValueTemp(:,n4);
%                                 else
%                                     VecValueTemp25(:,n5)=VecValueTemp(:,n4);
%                                     VecValueTemp25Temp(1,n5)={VecValueTemp2{1,n4}};
%                                 end
%                             end
%                         end
%                     end
                end
                ValueTime2=clock();
                ValueTimeTemp=(ValueTime2(1,4)-ValueTime(1,4))*60+ValueTime2(1,5)-ValueTime(1,5);
                VecValueTemp24=VecValueTemp24';
                VecValueTemp24Temp=VecValueTemp24;
                if size(VecValueTemp22,1)>=1
                    ValueTemp5=find(isnan(VecValueTemp22(:,2))==0);
                    ValueTemp5=size(ValueTemp5,1);
                else
                    ValueTemp5=0;
                end
                if size(VecValueTemp24,1)>=1
                    ValueTemp4=find(isnan(VecValueTemp24(:,2))==0);
                    VecResultsCoAuthors=[VecResultsCoAuthors;size(ValueTemp4,1) ValueTemp5 VecResultsEditor(1,16) size(ValueTemp4,1)/VecResultsEditor(1,16) ValueTemp5/VecResultsEditor(1,16)];
                else
                    VecResultsCoAuthors=[VecResultsCoAuthors;0 ValueTemp5 VecResultsEditor(1,16) 0 ValueTemp5/VecResultsEditor(1,16)];
                end
                VecValueTemp24=VecValueTemp25';
%                 if size(VecValueTemp22,2)>=1&&size(VecValueTemp23,2)>=1&&size(VecValueEditor{n1,22},2)<=3
                if size(VecValueTemp22,2)>=1&&size(VecValueTemp23,2)>=1&&size(VecValueEditor{n1,22},2)<=3&&VecResultsCoAuthors(end,1)<=15&&VecResultsCoAuthors(end,1)>=1
%                 if size(VecValueTemp22,2)>=1&&size(VecValueTemp23,2)>=1&&size(VecValueEditor{n1,22},2)<=3&&VecResultsCoAuthors(end,5)<=13
                    % First column of VecValueTemp22 and VecValueTemp23 correspond to after the arrivla of the editor while the second column corresponds to before.
                    VecFigure3=[VecFigure3;VecValueTemp22 VecValueTemp22(:,1)+VecValueTemp22(:,2) VecValueTemp22(:,1)-VecValueTemp22(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp22,1),1) n3*ones(size(VecValueTemp22,1),1) ones(size(VecValueTemp22,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp22,1),1) n1*ones(size(VecValueTemp22,1),1)];
                    VecFigure3=[VecFigure3;VecValueTemp23 VecValueTemp23(:,1)+VecValueTemp23(:,2) VecValueTemp23(:,1)-VecValueTemp23(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp23,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp23,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp23,1),1) n3*ones(size(VecValueTemp23,1),1) 2*ones(size(VecValueTemp23,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp23,1),1) n1*ones(size(VecValueTemp23,1),1)];
                    ValueTemp=find(VecValueTemp22(:,1)==0&VecValueTemp22(:,2)>0);
                    ValueTemp2=find(VecValueTemp23(:,1)==0&VecValueTemp23(:,2)>0);
                    VecFigure5=[VecFigure5;size(ValueTemp,1) size(VecValueTemp22,1) size(ValueTemp2,1) size(VecValueTemp23,1)];
                    VecResultsEditorCoAuthors=[VecResultsEditorCoAuthors;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                    if sum(VecValueTemp22(:,2))==0
                        if sum(VecValueTemp22(:,1))>0
                            VecResultsEditorsCoAuthorsTemp(1,1)=VecResultsEditorsCoAuthorsTemp(1,1)+1;
                        else
                            VecResultsEditorsCoAuthorsTemp(1,2)=VecResultsEditorsCoAuthorsTemp(1,2)+1;
                        end
                    else
                        if sum(VecValueTemp22(:,1))>0
                            VecResultsEditorsCoAuthorsTemp(1,3)=VecResultsEditorsCoAuthorsTemp(1,3)+1;
                        else
                            VecResultsEditorsCoAuthorsTemp(1,4)=VecResultsEditorsCoAuthorsTemp(1,4)+1;
                        end
                    end
                    if size(VecValueTemp24Temp,1)>=1
                        ValueTemp4=find(isnan(VecValueTemp24Temp(:,2))==0);
                        VecResultsCoAuthors3=[VecResultsCoAuthors3;size(ValueTemp4,1) ValueTemp5 VecResultsEditor(1,16) size(ValueTemp4,1)/VecResultsEditor(1,16) ValueTemp5/VecResultsEditor(1,16)];
                    else
                        VecResultsCoAuthors3=[VecResultsCoAuthors3;0 ValueTemp5 VecResultsEditor(1,16) 0 ValueTemp5/VecResultsEditor(1,16)];
                    end
                else
                    if size(VecValueEditor{n1,22},2)<=3
                        VecResultsEditorCoAuthors2=[VecResultsEditorCoAuthors2;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                    end
                end
%                 if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1&&size(VecValueEditor{n1,22},2)<=3
                if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1&&size(VecValueEditor{n1,22},2)<=3&&VecResultsCoAuthors(end,1)<=15&&VecResultsCoAuthors(end,1)>=1
%                 if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1&&size(VecValueEditor{n1,22},2)<=3&&VecResultsCoAuthors(end,4)<=50
                    % First column of VecValueTemp24 and VecValueTemp23 correspond to after the arrivla of the editor while the second column corresponds to before.
                    VecFigure2=[VecFigure2;VecValueTemp22 VecValueTemp22(:,1)+VecValueTemp22(:,2) VecValueTemp22(:,1)-VecValueTemp22(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp22,1),1) n3*ones(size(VecValueTemp22,1),1) ones(size(VecValueTemp22,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp22,1),1) n1*ones(size(VecValueTemp22,1),1)];
%                     VecFigure2=[VecFigure2;VecValueTemp24/n5Temp (VecValueTemp24(:,1)+VecValueTemp24(:,2)) (VecValueTemp24(:,1)-VecValueTemp24(:,2)) VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
                    VecFigure2=[VecFigure2;VecValueTemp24 VecValueTemp24(:,1)+VecValueTemp24(:,2) VecValueTemp24(:,1)-VecValueTemp24(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
                    VecResultsEditorJournal=[VecResultsEditorJournal;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                    if size(VecValueTemp24Temp,1)>=1
                        ValueTemp4=find(isnan(VecValueTemp24Temp(:,2))==0);
                        VecResultsCoAuthors2=[VecResultsCoAuthors2;size(ValueTemp4,1) ValueTemp5 VecResultsEditor(1,16) size(ValueTemp4,1)/VecResultsEditor(1,16) ValueTemp5/VecResultsEditor(1,16)];
                    else
                        VecResultsCoAuthors2=[VecResultsCoAuthors2;0 ValueTemp5 VecResultsEditor(1,16) 0 ValueTemp5/VecResultsEditor(1,16)];
                    end
                else
                    if size(VecValueEditor{n1,22},2)<=3
                        VecResultsEditorJournal2=[VecResultsEditorJournal2;VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                    end
                end
%                 % Robustness analysis (we average over the number of Nature journals)
%                 if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1&&size(VecValueEditor{n1,22},2)<=3&&n5Temp5>0
%                     % First column of VecValueTemp24 and VecValueTemp23 correspond to after the arrivla of the editor while the second column corresponds to before.
%                     VecFigure2=[VecFigure2;VecValueTemp22 VecValueTemp22(:,1)+VecValueTemp22(:,2) VecValueTemp22(:,1)-VecValueTemp22(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp22,1),1) n3*ones(size(VecValueTemp22,1),1) ones(size(VecValueTemp22,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp22,1),1) n1*ones(size(VecValueTemp22,1),1)];
% %                     VecFigure2=[VecFigure2;VecValueTemp24/n5Temp (VecValueTemp24(:,1)+VecValueTemp24(:,2))/n5Temp (VecValueTemp24(:,1)-VecValueTemp24(:,2))/n5Temp VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
%                     VecFigure2=[VecFigure2;VecValueTemp24/n5Temp5 VecValueTemp24(:,1)+VecValueTemp24(:,2) (VecValueTemp24(:,1)-VecValueTemp24(:,2))/n5Temp5 VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
%                 end
%             end
        end
    end
end

% [ValueResults,ValueResults2,stats]=fishertest([VecResultsEditorsCoAuthorsTemp(1,1) VecResultsEditorsCoAuthorsTemp(1,4);sum(VecResultsEditorsCoAuthorsTemp(1,1:4))-VecResultsEditorsCoAuthorsTemp(1,1) sum(VecResultsEditorsCoAuthorsTemp(1,1:4))-VecResultsEditorsCoAuthorsTemp(1,4)]);

% VecResultsEditorTemp=[];
% VecResultsEditorAfter=VecResultsEditorCoAuthors;
% VecResultsEditorBefore=VecResultsEditorCoAuthors2;
% for n1=1:3
%     ValueTemp=find(isnan(VecResultsEditorAfter(:,n1))==0);
%     ValueTemp2=find(isnan(VecResultsEditorBefore(:,n1))==0);
%     [ValueResults,ValueResults2]=ttest2(VecResultsEditorAfter(ValueTemp,n1),VecResultsEditorBefore(ValueTemp2,n1));
%     [ValueResults3,ValueResults4]=ranksum(VecResultsEditorAfter(ValueTemp,n1),VecResultsEditorBefore(ValueTemp2,n1));
%     VecResultsEditorTemp=[VecResultsEditorTemp;mean(VecResultsEditorAfter(ValueTemp,n1)) sqrt(var(VecResultsEditorAfter(ValueTemp,n1))) median(VecResultsEditorAfter(ValueTemp,n1)) quantile(VecResultsEditorAfter(ValueTemp,n1),0.25) quantile(VecResultsEditorAfter(ValueTemp,n1),0.75) mean(VecResultsEditorBefore(ValueTemp2,n1)) sqrt(var(VecResultsEditorBefore(ValueTemp2,n1))) median(VecResultsEditorBefore(ValueTemp2,n1)) quantile(VecResultsEditorBefore(ValueTemp2,n1),0.25) quantile(VecResultsEditorBefore(ValueTemp2,n1),0.75) ValueResults2 ValueResults3 size(ValueTemp,1) size(ValueTemp2,1)];
% end
% VecResultsEditorAfter=VecResultsEditorJournal;
% VecResultsEditorBefore=VecResultsEditorJournal2;
% for n1=1:3
%     ValueTemp=find(isnan(VecResultsEditorAfter(:,n1))==0);
%     ValueTemp2=find(isnan(VecResultsEditorBefore(:,n1))==0);
%     [ValueResults,ValueResults2]=ttest2(VecResultsEditorAfter(ValueTemp,n1),VecResultsEditorBefore(ValueTemp2,n1));
%     [ValueResults3,ValueResults4]=ranksum(VecResultsEditorAfter(ValueTemp,n1),VecResultsEditorBefore(ValueTemp2,n1));
%     VecResultsEditorTemp=[VecResultsEditorTemp;mean(VecResultsEditorAfter(ValueTemp,n1)) sqrt(var(VecResultsEditorAfter(ValueTemp,n1))) median(VecResultsEditorAfter(ValueTemp,n1)) quantile(VecResultsEditorAfter(ValueTemp,n1),0.25) quantile(VecResultsEditorAfter(ValueTemp,n1),0.75) mean(VecResultsEditorBefore(ValueTemp2,n1)) sqrt(var(VecResultsEditorBefore(ValueTemp2,n1))) median(VecResultsEditorBefore(ValueTemp2,n1)) quantile(VecResultsEditorBefore(ValueTemp2,n1),0.25) quantile(VecResultsEditorBefore(ValueTemp2,n1),0.75) ValueResults2 ValueResults3 size(ValueTemp,1) size(ValueTemp2,1)];
% end

VecFigure4=VecFigure;
% VecFigure=VecFigure2;
% VecFigure=VecFigureTemp;
VecFigureTemp=VecFigure;
VecFigure=VecFigure3;
ValueTemp=find(VecFigure(:,3)==0);
% ValueTemp=find(VecFigure(:,3)>8);
VecFigure(ValueTemp,:)=[];
[ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,5,3);
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,3,3); % Robustness analysis for the threshold used to remove homonyms 
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,4,3); % Robustness analysis for the threshold used to remove homonyms
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,6,3); % Robustness analysis for the threshold used to remove homonyms
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,7,3); % Robustness analysis for the threshold used to remove homonyms
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,5,4); % Analysis with the difference between after the editor's appointmenet and before (uncomment lines 275 to 277)
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,3,4);
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,4,4);
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,6,4);
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,7,4);
VecFigure=ValueTemp;
% [ValueTemp,ValueTemp2]=RemoveOutliers2(VecResultsCoAuthors,3,1); % To get the maximum number of co-authors of the editor

for n1=1:3
    ValueTemp=find(isnan(VecFigure(n1+4,:))==1);
    if size(ValueTemp,1)>0
        VecFigure(ValueTemp,:)=[];
        VecValueTemp(ValueTemp,:)=[];
    end
end
VecValueTemp=repmat('O',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==1);
VecValueTemp(ValueTemp,1)=repmat('E',size(ValueTemp,1),1);
% VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
% ValueResults=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
% ValueResults
TestTemp=0;
ValueTemp=1;
while ValueTemp<=max(VecFigure(:,11))&&TestTemp==0
    ValueTemp2=find(VecFigure(:,11)==ValueTemp);
    if size(ValueTemp2,1)>=1
        VecValueTemp2=VecFigure(ValueTemp2,:);
        if VecValueTemp2(1,9)==1
            TestTemp=1;
        end
    end
    ValueTemp=ValueTemp+1;
end
VecFigure(ValueTemp2,:)=[];
VecFigure=[VecValueTemp2;VecFigure];
VecValueTemp=repmat('O',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==1);
VecValueTemp(ValueTemp,1)=repmat('E',size(ValueTemp,1),1);
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel1=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
ValueTemp=find(VecValueTemp=='O');
VecFigure=[VecFigure(ValueTemp(1,1):end,:);VecFigure(1:ValueTemp(1,1)-1,:)];
VecValueTemp=[VecValueTemp(ValueTemp(1,1):end,:);VecValueTemp(1:ValueTemp(1,1)-1,:)];
% VecValueTemp4=table([VecFigure(:,1);VecFigure(:,2)],[VecValueTemp;VecValueTemp],[repmat('A',size(VecFigure,1),1);repmat('B',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
% ValueResultsModel1Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,2);VecFigure(:,1)],[VecValueTemp;VecValueTemp],[repmat('B',size(VecFigure,1),1);repmat('A',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel1Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,repmat('A',size(VecFigure,1),1),VecFigure(:,11),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel1Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
% ValueResultsModel1Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*Variable27+CategoryAuthor*Variable1+(1|Editor)','FitMethod','REML');
VecFigureTemp=VecFigure;
ValueTemp=find(VecFigureTemp(:,1)>=1);
VecFigureTemp(ValueTemp,1)=ones(size(ValueTemp,1),1);
ValueTemp=find(VecFigureTemp(:,2)>=1);
VecFigureTemp=VecFigureTemp(ValueTemp,:);
VecValueTemp=VecValueTemp(ValueTemp,:);
% VecValueTemp5=[VecValueTemp5(4:end,:);VecValueTemp5(1:3,:)]; % If commented, results are for authors who arrived before
% VecValueTemp=[VecValueTemp(4:end,:);VecValueTemp(1:3,:)]; % If commented, results are for authors who arrived before
% VecFigureTemp=[VecFigureTemp(4:end,:);VecFigureTemp(1:3,:)]; % If commented, results are for authors who arrived before
VecValueTemp4=table(VecFigureTemp(:,1),VecValueTemp,VecFigureTemp(:,2),VecFigureTemp(:,11),'VariableNames',{'ArticlesAfter','CategoryAuthor','ArticlesBefore','Editor'});
% ValueResultsModel1Temp3=fitglme(VecValueTemp4,'ArticlesAfter~CategoryAuthor+ArticlesBefore+(1|Editor)','Distribution','Binomial','Link','logit','BinomialSize',1,'Weights',ones(size(VecFigureTemp,1),1),'FitMethod','laplace');
% % ValueResultsModel1Temp3=fitglme(VecValueTemp4,'ArticlesAfter~CategoryAuthor*ArticlesBefore+(1|Editor)','Distribution','Binomial','Link','logit','BinomialSize',1,'Weights',ones(size(VecFigureTemp,1),1),'FitMethod','laplace');

return

TestTemp=0;
ValueTemp=1;
while ValueTemp<=max(VecFigure(:,11))&&TestTemp==0
    ValueTemp2=find(VecFigure(:,11)==ValueTemp);
    if size(ValueTemp2,1)>=1
        VecValueTemp2=VecFigure(ValueTemp2,:);
        if VecValueTemp2(1,9)==2
            TestTemp=1;
        end
    end
    ValueTemp=ValueTemp+1;
end
VecFigure(ValueTemp2,:)=[];
VecFigure=[VecValueTemp2;VecFigure];
VecValueTemp=repmat('E',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==2);
VecValueTemp(ValueTemp,1)=repmat('O',size(ValueTemp,1),1);
% Model for the analysis comparing the number of articles of former co-authors and the ther authors in the editor's journal
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel2=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,1);VecFigure(:,2)],[VecValueTemp;VecValueTemp],[repmat('A',size(VecFigure,1),1);repmat('B',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel2Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,2);VecFigure(:,1)],[VecValueTemp;VecValueTemp],[repmat('B',size(VecFigure,1),1);repmat('A',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel2Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
for n1=1:3
    ValueTemp=find(isnan(VecFigure(n1+4,:))==1);
    if size(ValueTemp,1)>0
        VecFigure(ValueTemp,:)=[];
        VecValueTemp(ValueTemp,:)=[];
    end
end
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel3=fitlme(VecValueTemp4,'Articles~CategoryAuthor*Variable1+CategoryAuthor*Variable27+(1|Editor)','FitMethod','REML');

return

% % Saving data for sharing
% VecValueTemp=repmat('E',size(VecFigure,1),1);
% ValueTemp=find(VecFigure(:,9)==2);
% VecValueTemp(ValueTemp,1)=repmat('O',size(ValueTemp,1),1);
% VecFigure=[VecFigure(:,4) VecFigure(:,11)];
% save('C:\Users\Remy Neveu\Desktop\Tests_R\AnalyseEtudeIRM\Nature\Statistical analyses\2nd set of results\AnalyseMixedModelCoAuthorsEditorJournal.mat','VecFigure','VecValueTemp');

VecFigure=VecFigure2;
ValueTemp=find(VecFigure(:,3)==0);
% ValueTemp=find(VecFigure(:,3)>8);
VecFigure(ValueTemp,:)=[];
% ValueTemp=find(abs(VecFigure(:,3)-mean(VecFigure(:,3)))<3*sqrt(var(VecFigure(:,3))));
% VecFigure=VecFigure(ValueTemp,:);
[ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,5,3);
VecFigure=ValueTemp;
for n1=1:3
    ValueTemp=find(isnan(VecFigure(n1+4,:))==1);
    if size(ValueTemp,1)>0
        VecFigure(ValueTemp,:)=[];
        VecValueTemp(ValueTemp,:)=[];
    end
end
VecValueTemp=repmat('O',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==1);
VecValueTemp(ValueTemp,1)=repmat('E',size(ValueTemp,1),1);
% VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
% ValueResults=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
% ValueResults
TestTemp=0;
ValueTemp=1;
while ValueTemp<=max(VecFigure(:,11))&&TestTemp==0
    ValueTemp2=find(VecFigure(:,11)==ValueTemp);
    if size(ValueTemp2,1)>=1
        VecValueTemp2=VecFigure(ValueTemp2,:);
        if VecValueTemp2(1,9)==1
            TestTemp=1;
        end
    end
    ValueTemp=ValueTemp+1;
end
VecFigure(ValueTemp2,:)=[];
VecFigure=[VecValueTemp2;VecFigure];
VecValueTemp=repmat('O',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==1);
VecValueTemp(ValueTemp,1)=repmat('E',size(ValueTemp,1),1);
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel4=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,1);VecFigure(:,2)],[VecValueTemp;VecValueTemp],[repmat('A',size(VecFigure,1),1);repmat('B',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel4Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,2);VecFigure(:,1)],[VecValueTemp;VecValueTemp],[repmat('B',size(VecFigure,1),1);repmat('A',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel4Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
TestTemp=0;
ValueTemp=1;
while ValueTemp<=max(VecFigure(:,11))&&TestTemp==0
    ValueTemp2=find(VecFigure(:,11)==ValueTemp);
    if size(ValueTemp2,1)>=1
        VecValueTemp2=VecFigure(ValueTemp2,:);
        if VecValueTemp2(1,9)==2
            TestTemp=1;
        end
    end
    ValueTemp=ValueTemp+1;
end
VecFigure(ValueTemp2,:)=[];
VecFigure=[VecValueTemp2;VecFigure];
VecValueTemp=repmat('E',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==2);
VecValueTemp(ValueTemp,1)=repmat('O',size(ValueTemp,1),1);
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel5=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,1);VecFigure(:,2)],[VecValueTemp;VecValueTemp],[repmat('A',size(VecFigure,1),1);repmat('B',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel5Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,2);VecFigure(:,1)],[VecValueTemp;VecValueTemp],[repmat('B',size(VecFigure,1),1);repmat('A',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel5Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
for n1=1:3
    ValueTemp=find(isnan(VecFigure(n1+4,:))==1);
    if size(ValueTemp,1)>0
        VecFigure(ValueTemp,:)=[];
        VecValueTemp(ValueTemp,:)=[];
    end
end
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel6=fitlme(VecValueTemp4,'Articles~CategoryAuthor*Variable1+CategoryAuthor*Variable27+(1|Editor)','FitMethod','REML');

% % Saving data for sharing
% VecValueTemp=repmat('E',size(VecFigure,1),1);
% ValueTemp=find(VecFigure(:,9)==2);
% VecValueTemp(ValueTemp,1)=repmat('O',size(ValueTemp,1),1);
% VecFigure=[VecFigure(:,4) VecFigure(:,11)];
% save('C:\Users\Remy Neveu\Desktop\Tests_R\AnalyseEtudeIRM\Nature\Statistical analyses\2nd set of results\AnalyseMixedModelCoAuthorsOnlyAllJournals.mat','VecFigure','VecValueTemp');

return

[ValueResults2,ValueResults2Temp]=ttest(VecFigure5(:,1)./VecFigure5(:,2)-VecFigure5(:,3)./VecFigure5(:,4))
[ValueResults2,ValueResults2Temp]=signrank(VecFigure5(:,1)./VecFigure5(:,2)-VecFigure5(:,3)./VecFigure5(:,4))

VecFigure=[];
VecFigure2=[];
VecFigure3=[];
VecFigure5=[];
for n1=1:323
    n1
    ValueTemp=find(VecDistribution(:,1)==n1);
    ValueStartEditor=VecValueEditor{n1,22};
    n5Temp5=0;
    if size(ValueTemp,1)==1&&n1~=11
        if VecDistribution(ValueTemp,2)<=ValueCutoff
            ValueJournal=VecValueEditor{n1,11};
            n3=1;
            TestTemp=0;
            while n3<=size(VecValueJournal,1)&&TestTemp==0
                if strcmpi(ValueJournal,VecValueJournal{n3,1})==1
                    TestTemp=1;
                else
                    n3=n3+1;
                end
            end
            load([ValueFolderTemp2 'FileAnalysisEditorCoAuthors' num2str(n1) 'RestrictedYear2Month8.mat']);
            load([ValueFolderTemp2 'FileAnalysisCharacteristicsEditor' num2str(n1) '.mat']);
            VecValueTemp24=[];
            VecValueTemp25=[];
            VecValueTemp24Temp=[];
            VecValueTemp25Temp=[];
            ValueTime=clock();
            for n2=1:33
                if n2==n3
                    eval(['VecValueTemp=VecResultsCoAuthors' num2str(n2) 'j1y1m2Filtered;']);
                    VecValueTemp22=VecValueTemp';
                    eval(['VecValueTemp=VecResultsOtherAuthors' num2str(n2) 'j1y1m2Filtered;']);
                    VecValueTemp23=VecValueTemp';
                else
                    eval(['VecValueTemp=VecResultsCoAuthors' num2str(n2) 'j1y1m1Filtered;']);
                    if size(VecValueTemp24,2)==0&&size(VecValueTemp,2)>=1
                        VecValueTemp24=VecValueTemp;
                        eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1mFiltered;']);
                        VecValueTemp24Temp=VecValueTemp2;
                    else
                        if size(VecValueTemp,2)>=1
                            eval(['VecValueTemp2=VecResultsNameCoAuthors' num2str(n2) 'j1y1mFiltered;']);
                            for n4=1:size(VecValueTemp2,2)
                                n5=1;
                                TestTemp=0;
                                while TestTemp==0&&n5<=size(VecValueTemp24Temp,2)
                                    if size(VecValueTemp24Temp{1,n5},2)==size(VecValueTemp2{1,n4},2)&&sum(abs(VecValueTemp24Temp{1,n5}-VecValueTemp2{1,n4}))==0
                                        TestTemp=1;
                                    else
                                        n5=n5+1;
                                    end
                                end
                                if n5<=size(VecValueTemp24Temp,2)
                                    VecValueTemp24(:,n5)=VecValueTemp24(:,n5)+VecValueTemp(:,n4);
                                else
                                    VecValueTemp24(:,n5)=VecValueTemp(:,n4);
                                    VecValueTemp24Temp(1,n5)={VecValueTemp2{1,n4}};
                                end
                            end
                            if size(VecValueTemp2,2)>0
                                n5Temp5=n5Temp5+1;
                            end
                        end
                    end
                end
            end
            ValueTime2=clock();
            ValueTimeTemp=(ValueTime2(1,4)-ValueTime(1,4))*60+ValueTime2(1,5)-ValueTime(1,5);
            VecValueTemp24=VecValueTemp24';
            VecValueTemp25=VecValueTemp25';
            if size(VecValueTemp22,2)>=1&&size(VecValueTemp23,2)>=1&&size(VecValueEditor{n1,22},2)<=3
                % First column of VecValueTemp22 and VecValueTemp23 correspond to after the arrivla of the editor while the second column corresponds to before.
                VecFigure3=[VecFigure3;VecValueTemp22 VecValueTemp22(:,1)+VecValueTemp22(:,2) VecValueTemp22(:,1)-VecValueTemp22(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp22,1),1) n3*ones(size(VecValueTemp22,1),1) ones(size(VecValueTemp22,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp22,1),1) n1*ones(size(VecValueTemp22,1),1)];
                VecFigure3=[VecFigure3;VecValueTemp23 VecValueTemp23(:,1)+VecValueTemp23(:,2) VecValueTemp23(:,1)-VecValueTemp23(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp23,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp23,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp23,1),1) n3*ones(size(VecValueTemp23,1),1) 2*ones(size(VecValueTemp23,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp23,1),1) n1*ones(size(VecValueTemp23,1),1)];
                ValueTemp=find(VecValueTemp22(:,1)==0&VecValueTemp22(:,2)>0);
                ValueTemp2=find(VecValueTemp23(:,1)==0&VecValueTemp23(:,2)>0);
                VecFigure5=[VecFigure5;size(ValueTemp,1) size(VecValueTemp22,1) size(ValueTemp2,1) size(VecValueTemp23,1)];
            end
            if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1&&size(VecValueEditor{n1,22},2)<=3
                % First column of VecValueTemp24 and VecValueTemp23 correspond to after the arrivla of the editor while the second column corresponds to before.
                VecFigure2=[VecFigure2;VecValueTemp22 VecValueTemp22(:,1)+VecValueTemp22(:,2) VecValueTemp22(:,1)-VecValueTemp22(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp22,1),1) n3*ones(size(VecValueTemp22,1),1) ones(size(VecValueTemp22,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp22,1),1) n1*ones(size(VecValueTemp22,1),1)];
%                     VecFigure2=[VecFigure2;VecValueTemp24/n5Temp (VecValueTemp24(:,1)+VecValueTemp24(:,2))/n5Temp (VecValueTemp24(:,1)-VecValueTemp24(:,2))/n5Temp VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
                VecFigure2=[VecFigure2;VecValueTemp24 VecValueTemp24(:,1)+VecValueTemp24(:,2) VecValueTemp24(:,1)-VecValueTemp24(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
            end
%             % Robustness analysis (we average over the number of Nature journals)
%             if size(VecValueTemp24,2)>=1&&size(VecValueTemp22,2)>=1&&size(VecValueEditor{n1,22},2)<=3&&n5Temp5>0
%                 % First column of VecValueTemp24 and VecValueTemp23 correspond to after the arrivla of the editor while the second column corresponds to before.
%                 VecFigure2=[VecFigure2;VecValueTemp22 VecValueTemp22(:,1)+VecValueTemp22(:,2) VecValueTemp22(:,1)-VecValueTemp22(:,2) VecResultsEditor(1,1)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp22,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp22,1),1) n3*ones(size(VecValueTemp22,1),1) ones(size(VecValueTemp22,1),1) size(VecValueTemp22,1)*ones(size(VecValueTemp22,1),1) n1*ones(size(VecValueTemp22,1),1)];
% %                     VecFigure2=[VecFigure2;VecValueTemp24/n5Temp (VecValueTemp24(:,1)+VecValueTemp24(:,2))/n5Temp (VecValueTemp24(:,1)-VecValueTemp24(:,2))/n5Temp VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
%                 VecFigure2=[VecFigure2;VecValueTemp24/n5Temp5 VecValueTemp24(:,1)+VecValueTemp24(:,2) (VecValueTemp24(:,1)-VecValueTemp24(:,2))/n5Temp5 VecResultsEditor(1,1)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,16)*ones(size(VecValueTemp24,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp24,1),1) n3*ones(size(VecValueTemp24,1),1) 2*ones(size(VecValueTemp24,1),1) size(VecValueTemp24,1)*ones(size(VecValueTemp24,1),1) n1*ones(size(VecValueTemp24,1),1)];
%             end
        end
    end
end

VecFigure=VecFigure3;
ValueTemp=find(VecFigure(:,3)==0);
% ValueTemp=find(VecFigure(:,3)>8);
VecFigure(ValueTemp,:)=[];
[ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,5,3);
VecFigure=ValueTemp;
for n1=1:3
    ValueTemp=find(isnan(VecFigure(n1+4,:))==1);
    if size(ValueTemp,1)>0
        VecFigure(ValueTemp,:)=[];
        VecValueTemp(ValueTemp,:)=[];
    end
end
VecValueTemp=repmat('O',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==1);
VecValueTemp(ValueTemp,1)=repmat('E',size(ValueTemp,1),1);
% VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
% ValueResults=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
% ValueResults
TestTemp=0;
ValueTemp=1;
while ValueTemp<=max(VecFigure(:,11))&&TestTemp==0
    ValueTemp2=find(VecFigure(:,11)==ValueTemp);
    if size(ValueTemp2,1)>=1
        VecValueTemp2=VecFigure(ValueTemp2,:);
        if VecValueTemp2(1,9)==1
            TestTemp=1;
        end
    end
    ValueTemp=ValueTemp+1;
end
VecFigure(ValueTemp2,:)=[];
VecFigure=[VecValueTemp2;VecFigure];
VecValueTemp=repmat('O',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==1);
VecValueTemp(ValueTemp,1)=repmat('E',size(ValueTemp,1),1);
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel1=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,1);VecFigure(:,2)],[VecValueTemp;VecValueTemp],[repmat('A',size(VecFigure,1),1);repmat('B',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel1Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,2);VecFigure(:,1)],[VecValueTemp;VecValueTemp],[repmat('B',size(VecFigure,1),1);repmat('A',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel1Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
TestTemp=0;
ValueTemp=1;
while ValueTemp<=max(VecFigure(:,11))&&TestTemp==0
    ValueTemp2=find(VecFigure(:,11)==ValueTemp&VecFigure(:,9)==2);
    if size(ValueTemp2,1)>=1
        VecValueTemp2=VecFigure(ValueTemp2,:);
        if VecValueTemp2(1,9)==2
            TestTemp=1;
        end
    end
    ValueTemp=ValueTemp+1;
end
VecFigure(ValueTemp2,:)=[];
VecFigure=[VecValueTemp2;VecFigure];
VecValueTemp=repmat('E',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==2);
VecValueTemp(ValueTemp,1)=repmat('O',size(ValueTemp,1),1);
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel2=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,1);VecFigure(:,2)],[VecValueTemp;VecValueTemp],[repmat('A',size(VecFigure,1),1);repmat('B',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel2Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,2);VecFigure(:,1)],[VecValueTemp;VecValueTemp],[repmat('B',size(VecFigure,1),1);repmat('A',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel2Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
for n1=1:3
    ValueTemp=find(isnan(VecFigure(n1+4,:))==1);
    if size(ValueTemp,1)>0
        VecFigure(ValueTemp,:)=[];
        VecValueTemp(ValueTemp,:)=[];
    end
end
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel3=fitlme(VecValueTemp4,'Articles~CategoryAuthor*Variable1+CategoryAuthor*Variable27+(1|Editor)','FitMethod','REML');

VecFigure=VecFigure2;
ValueTemp=find(VecFigure(:,3)==0);
% ValueTemp=find(VecFigure(:,3)>8);
VecFigure(ValueTemp,:)=[];
[ValueTemp,ValueTemp2]=RemoveOutliers2(VecFigure,5,3);
VecFigure=ValueTemp;
for n1=1:3
    ValueTemp=find(isnan(VecFigure(n1+4,:))==1);
    if size(ValueTemp,1)>0
        VecFigure(ValueTemp,:)=[];
        VecValueTemp(ValueTemp,:)=[];
    end
end
VecValueTemp=repmat('O',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==1);
VecValueTemp(ValueTemp,1)=repmat('E',size(ValueTemp,1),1);
% VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
% ValueResults=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
% ValueResults
TestTemp=0;
ValueTemp=1;
while ValueTemp<=max(VecFigure(:,11))&&TestTemp==0
    ValueTemp2=find(VecFigure(:,11)==ValueTemp);
    if size(ValueTemp2,1)>=1
        VecValueTemp2=VecFigure(ValueTemp2,:);
        if VecValueTemp2(1,9)==1
            TestTemp=1;
        end
    end
    ValueTemp=ValueTemp+1;
end
VecFigure(ValueTemp2,:)=[];
VecFigure=[VecValueTemp2;VecFigure];
VecValueTemp=repmat('O',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==1);
VecValueTemp(ValueTemp,1)=repmat('E',size(ValueTemp,1),1);
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel4=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,1);VecFigure(:,2)],[VecValueTemp;VecValueTemp],[repmat('A',size(VecFigure,1),1);repmat('B',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel4Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,2);VecFigure(:,1)],[VecValueTemp;VecValueTemp],[repmat('B',size(VecFigure,1),1);repmat('A',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel4Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
TestTemp=0;
ValueTemp=1;
while ValueTemp<=max(VecFigure(:,11))&&TestTemp==0
    ValueTemp2=find(VecFigure(:,11)==ValueTemp&VecFigure(:,9)==2);
    if size(ValueTemp2,1)>=1
        VecValueTemp2=VecFigure(ValueTemp2,:);
        if VecValueTemp2(1,9)==2
            TestTemp=1;
        end
    end
    ValueTemp=ValueTemp+1;
end
VecFigure(ValueTemp2,:)=[];
VecFigure=[VecValueTemp2;VecFigure];
VecValueTemp=repmat('E',size(VecFigure,1),1);
ValueTemp=find(VecFigure(:,9)==2);
VecValueTemp(ValueTemp,1)=repmat('O',size(ValueTemp,1),1);
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel5=fitlme(VecValueTemp4,'Articles~CategoryAuthor+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,1);VecFigure(:,2)],[VecValueTemp;VecValueTemp],[repmat('A',size(VecFigure,1),1);repmat('B',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel5Temp=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
VecValueTemp4=table([VecFigure(:,2);VecFigure(:,1)],[VecValueTemp;VecValueTemp],[repmat('B',size(VecFigure,1),1);repmat('A',size(VecFigure,1),1)],[VecFigure(:,11);VecFigure(:,11)],'VariableNames',{'Articles','CategoryAuthor','CategoryArticle','Editor'});
ValueResultsModel5Temp2=fitlme(VecValueTemp4,'Articles~CategoryAuthor*CategoryArticle+(1|Editor)','FitMethod','REML');
for n1=1:3
    ValueTemp=find(isnan(VecFigure(n1+4,:))==1);
    if size(ValueTemp,1)>0
        VecFigure(ValueTemp,:)=[];
        VecValueTemp(ValueTemp,:)=[];
    end
end
VecValueTemp4=table(VecFigure(:,4),VecFigure(:,5),VecFigure(:,6),VecFigure(:,7),VecValueTemp,VecFigure(:,11),VecFigure(:,10),'VariableNames',{'Articles','Variable1','Variable16','Variable27','CategoryAuthor','Editor','CoAuthors'});
ValueResultsModel6=fitlme(VecValueTemp4,'Articles~CategoryAuthor*Variable1+CategoryAuthor*Variable27+(1|Editor)','FitMethod','REML');

% save([ValueFolderTemp2 'ResultsFourthLevelEditorCoAuthorsFiltered.mat'],'ValueResultsModel1','ValueResultsModel1Temp','ValueResultsModel1Temp2','ValueResultsModel2','ValueResultsModel2Temp','ValueResultsModel2Temp2','ValueResultsModel3','ValueResultsModel4','ValueResultsModel4Temp','ValueResultsModel4Temp2','ValueResultsModel5','ValueResultsModel5Temp','ValueResultsModel5Temp2','ValueResultsModel6');

% save([ValueFolderTemp2 'AnalyseMixedModelFourthLevelCoAuthorsNonFiltered.mat'],'VecFigure');




